<template>
    <div style="margin: 0px auto">
        <h1 align="center">添加商品分类</h1>
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
            <el-form-item label="分类名称" prop="name">
                <el-input v-model="form"></el-input>
            </el-form-item>
            <el-form-item label="店铺名称" prop="dipuname">
                <el-input v-model="form.name"></el-input>
            </el-form-item>
            <el-form-item label="分类级别" prop="rank">
                <el-select v-model="form.ID" placeholder="请选择" style="width: 300px">
                    <!--分类级别-->
                    <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item style="margin-left: 100px;margin: 0px auto">
                <el-button type="primary" @click="submitForm('form')">立即添加</el-button>
                <el-button @click="resetForm('form')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: "addcommodity",
        data() {
            return {
                form: {
                    ID: '',
                    //分店名称
                    name: '',
                    //一级分类
                    classone: '',
                    //二级分类
                    classtwe: '',
                    //三级分类
                    classthree: ''
                }
                ,
                options: [{
                    //一级分类
                    classone: '',
                    //二级分类
                    classtwe: '',
                    //三级分类
                    classthree: ''
                }],
                value: ''
            }
        },
        methods: {
            //立即创建方法
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        window.console.log('error submit!!');
                        return false;
                    }
                });
            },
            //添加方法
            add: function (form) {
                this.axios.post("http://localhost:8686/", form).then(response => {
                    if (response.data != null) {
                        alert("添加成功");
                    } else {
                        alert("添加失败");
                    }
                }).catch((error) => {
                    alert(error)
                });
            }
            ,
            //重置方法
            resetForm(form) {
                this.$refs[form].resetFields();
            }
        },
        created: function () {
            this.axios.post("http://localhost:8686//").then(response => {
                alert(response.data);
                this.options = response.data
            });
        },
    }
</script>

<style scoped>

</style>